﻿using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WinFormsApp1.Models
    {
        public class ButtonCollection
        {
            public static int Span = 0;
            public ButtonCollection()
            {
                Rows = new List<RowItem> { new() };
            }
            /// <summary>
            /// 当前行的索引
            /// </summary>
            public int RowIndex { get; set; }
            /// <summary>
            /// 已占用的总高度
            /// </summary>
            public int TotalHeight { get; set; }

            public int CurrentRowTotalWidth
            {
                get
                {
                    if (Rows.Count <= 0)
                    {
                        return 0;
                    }
                    return Rows[RowIndex].TotalWidth;
                }
            }

            public List<RowItem> Rows { get; set; }
            public int TotalButtonCount { get; set; }
        }

        public class RowItem
        {
            public RowItem()
            {
                Buttons = new List<Button>();
            }
            /// <summary>
            /// 当前行中按钮集合
            /// </summary>
            public List<Button> Buttons { get; private set; }

            public void AddButton(Button button)
            {
                Buttons.Add(button);
            }
            /// <summary>
            /// 当前行的最大高度
            /// </summary>
            public int MaxHeight
            {
                get
                {
                    return Buttons.Max(x => x.Height);
                }
            }
            /// <summary>
            /// 当前行中所有按钮使用的宽度总和
            /// </summary>
            public int TotalWidth
            {
                get
                {
                    if (Buttons.Count <= 0)
                    {
                        return 0;
                    }
                    return (Buttons.Sum(x => x.Width) + (Buttons.Count * ButtonCollection.Span - ButtonCollection.Span));
                }
            }
        }
    }